/*
 * morestring.h
 *
 *  Created on: Sep 8, 2008
 *      Author: lindenb
 */

#ifndef MORESTRING_HEADER
#define MORESTRING_HEADER
#include <stdio.h>
#include <string.h>
/** a string that should be free with <code>Free(void* ptr)</code> */
typedef char* malloc_string;

typedef struct StringArray_t
    {
    malloc_string* _data;
    int _size;
    }StringArray,*StringArrayPtr;

extern StringArrayPtr stringArray_new();
extern StringArrayPtr strSplit(const char* line,int c);
extern int stringArray_size(StringArrayPtr ptr);
extern const char* stringArray_at(StringArrayPtr ptr,int index);
extern int stringArray_addElement(StringArrayPtr ptr,const char*);
extern void stringArray_delete(StringArrayPtr ptr);

extern char* ltrim(char *);
extern char* rtrim(char *);
extern char* trim(char *);
extern malloc_string strfmt(const char* fmt,...);
extern int strIsEmpty(const char* s);
extern int strLastIndexOfChar(const char* s,int c);
extern int strLastIndexOfString(const char* s,const char* search);
extern malloc_string substr(const char* s,int start,int end);
extern malloc_string readline(FILE *in);
extern int strIsInteger(const char* s);
extern malloc_string strAppendString(malloc_string str,const char* what);
extern malloc_string strAppendChar(malloc_string str,char what);
/** print a C string escaping C char
 * @param s the string
 * @param out the stream where the string will be written
 * */
extern int strPrintEscape(const char* s, FILE* out);
/**
 * @param s the string
 * @param substr the substring
 * @return 1 if s starts with substr
 */
extern int strStartsWith(const char* s, const char* substr);
#endif /* MORESTRING_H_ */
